import axios from 'axios'
export default value => {
  let path = `/api/book-content/${value}/`
  let detailsContent = {}
  return axios.get(path)
    .then(response => {
      let data = response.data
      detailsContent.title = data
        .match(/<p><a href="\/info-.*\/"><h2>.*<\/h2><\/a>/g, '')
        .join('')
        .replace(/<p><a href="\/info-.*\/"><h2>/g, '')
        .replace(/<\/h2><\/a>/g, '')
      detailsContent.author = data
        .match(/<a href="\/author\/.*">.*<\/a>/g, '')
        .join('')
        .replace(/<a href="\/author\/.*">/g, '')
        .replace(/<\/a>/g, '')
      detailsContent.date = data
        .match(/<p>更新：.*<\/p>/g, '')
        .join('')
        .replace(/<p>更新：/g, '')
        .replace(/<\/p>/g, '')
      detailsContent.chapter = data
        .match(/<a href="\/wapbook-.*\/">.*<\/a>/g, '')
        .join('')
        .replace(/<a href="\/wapbook-.*\/">/g, '')
        .replace(/<span><\/span><\/a>.*/g, '')
      detailsContent.firstChapterId = data
        .match(/<a href="\/wapbook-.*-.*\/">开始阅读<\/a>/g, '')
        .join('')
        .replace(/<a href="\/wapbook-.*-/g, '')
        .replace(/\/">开始阅读<\/a>.*/g, '')
      detailsContent.id = data
        .match(/<a href="\/wapbook-.*-.*\/">开始阅读<\/a>/g, '')
        .join('')
        .replace(/<a href="\/wapbook-/g, '')
        .replace(/-.*\/">开始阅读<\/a>.*/g, '')
      detailsContent.cover = data
        .match(/<div class="block_img2"><img src=".*"\/><\/div>/g, '')
        .join('')
        .replace(/<div class="block_img2"><img src="/g, '')
        .replace(/" border="0" width='85' height='100' onerror="this.src='\/static\/images\/no_photo.jpg'"\/><\/div>/g, '')
      detailsContent.intro = data
        .match(/<div class="intro_info">.*/g, '')
        .join('')
        .replace(/<div class="intro_info">/g, '')
        .replace(/<.*>/g, '')
      let chapterDirectory = data.match(/<a href="\/wapbook-.*-.*\/">.*<span><\/span><\/a>/g, '')
      let chapterDirectoryWrapper = []
      let chapterDirectoryWrapperItem = ''
      for (let i = 0; i < chapterDirectory.length; i++) {
        chapterDirectoryWrapperItem = chapterDirectory[i]
          .replace(/<a href="\/wapbook-.*-.*\/">/g, '')
          .replace(/<span><\/span><\/a>/g, '')
        chapterDirectoryWrapper.push(chapterDirectoryWrapperItem)
      }
      detailsContent.chapterDirectory = chapterDirectoryWrapper
      return detailsContent
    })
}
